<?php
namespace app\index\controller;
use think\Controller;
use think\Db;
use think\Session;

class Active extends Controller
{
    public function enlist(){
        return $this->view->fetch();
    }
    public function enlist_btn(){
        $data = array(
          'username' => $_POST['username'],
          'sex' => $_POST['sex'],
          'tel' => $_POST['tel'],
          'place' => $_POST['place']
        );

        $info = Db::table('tp_enlist')->where('tel',$_POST['tel'])->find();

        if($info['tel']){
            return json(['code' => -1, 'msg' => '您已在'.$info['place'].'报名，请勿重复报名！']);
        }else{
            $res = Db::table('tp_enlist')->insert($data);
            if($res){
                return json(['code' => 200, 'msg' => '报名成功！']);
            }else{
                return json(['code' => -200, 'msg' => '系统繁忙，请稍后再试！']);
            }
        }
    }
}
